package com.product.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.product.trace.VO.ProductOut2VO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.product.common.annotation.Log;
import com.product.common.core.controller.BaseController;
import com.product.common.core.domain.AjaxResult;
import com.product.common.enums.BusinessType;
import com.product.trace.domain.ProductInto;
import com.product.trace.service.IProductIntoService;
import com.product.common.utils.poi.ExcelUtil;
import com.product.common.core.page.TableDataInfo;

/**
 * 商品采购详情Controller
 *
 * @author wanghui
 * @date 2022-08-22
 */
@RestController
@RequestMapping("/trace/productInto")
public class ProductIntoController extends BaseController {
    @Autowired
    private IProductIntoService productIntoService;

    /**
     * 查询商品采购详情列表
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductInto productInto) {
        startPage();
        List<ProductInto> list = productIntoService.selectProductIntoList(productInto);
        return getDataTable(list);
    }

    /**
     * @param productInto 产品进
     * @return {@link TableDataInfo }
     * @Description 获取通过检查的信息
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:list')")
    @GetMapping("/listpass")
    public TableDataInfo listCheckPass(ProductInto productInto) {
        startPage();
        productInto.setCommodityStatus("0");
        List<ProductInto> list = productIntoService.selectProductIntoList(productInto);
        return getDataTable(list);
    }

    /**
     * @param product
     * @return {@link TableDataInfo }
     * @Description 重新获取采购产品列表
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(ProductOut2VO product) {
        startPage();
        List<ProductOut2VO> list = productIntoService.getAllProductList(product);
        return getDataTable(list);
    }

    /**
     * 导出商品采购详情列表
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:export')")
    @Log(title = "商品采购详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductInto productInto) {
        List<ProductInto> list = productIntoService.selectProductIntoList(productInto);
        ExcelUtil<ProductInto> util = new ExcelUtil<ProductInto>(ProductInto.class);
        util.exportExcel(response, list, "商品采购详情数据");
    }

    /**
     * 获取商品采购详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(productIntoService.selectProductIntoById(id));
    }

    /**
     * 新增商品采购详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:add')")
    @Log(title = "商品采购详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductInto productInto) {
        return toAjax(productIntoService.insertProductInto(productInto));
    }

    /**
     * 修改商品采购详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:edit')")
    @Log(title = "商品采购详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductInto productInto) {
        return toAjax(productIntoService.updateProductInto(productInto));
    }

    /**
     * 删除商品采购详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productInto:remove')")
    @Log(title = "商品采购详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(productIntoService.deleteProductIntoByIds(ids));
    }
}
